<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>

<form:form commandName="excelData" cssClass="form-horizontal" role="form">
	<div class="panel panel-default">
        <%--抄送领导--%>
		<input type="hidden" id="caosongshuju"  value="${excelData.cell8}" />
		<%--牵头单位--%>
		<input type="hidden" id="qiantoushuju"     value="${excelData.cell6}" />
		<%--协办单位--%>
		<input type="hidden"id="xiebanshuju"     value="${excelData.cell7}" />
			<input type="hidden"   id="pt-batchNum"     value="${excelData.batchNum}" />
		<div class="panel-body">

			<div class="form-group">

				<label class="col-sm-2 control-label no-padding-right" for="excelData"><font color="red">校验信息</font></label>
				<div class="col-sm-10">
					<textarea rows="3" cols="70" class="chance_remarks"  readonly>${excelData.remarks}"</textarea>
				</div>
			</div>

			<div class="form-group">

				<label class="col-sm-2 control-label no-padding-right" for="excelData">事项<font color="red">*</font></label>
				<div class="col-sm-10">
					<textarea rows="5" cols="70" name="cell0" class="chance1_1_17">${excelData.cell0}"</textarea>
				</div>
			</div>
<%--            <div class="form-group">--%>
<%--				<label class="col-sm-2 control-label no-padding-right" for="excelData">抄送领导</label>--%>
<%--				<div class="col-sm-8" id="caosonglingdaoid">--%>
<%--						&lt;%&ndash;					<input type="number" name="ruleRatio"  min="0" max="100" placeholder="占比"  value="${excelData.cell5}" class="form-control" required >&ndash;%&gt;--%>
<%--				</div>--%>
<%--			</div>--%>
			<div class="form-group">
				<label class="col-sm-2 control-label no-padding-right" for="excelData">督查组单位</label>
				<div class="col-sm-8">
					<select name="cell10">
						<option value="">请选择</option>
						<c:forEach items="${groups}" var="group">
							<option value="${group.sysId}">${group.deptName}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="form-group">

				<label class="col-sm-2 control-label no-padding-right" for="excelData">牵头单位<font color="red">*</font></label>
				<div class="col-sm-8" id="qiantoudanweiid">
<%--					<input type="text"  name="ruleName"   value="${excelData.cell1}" min="0" max="100" placeholder="评价" class="form-control" required >--%>
				</div>

			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label no-padding-right" for="excelData">协办单位</label>
				<div class="col-sm-8" id="xiebandanweiid">
						<%--					<input type="text" name="ruleRatio"  placeholder="占比"  value="${excelData.cell2}" class="form-control" required >--%>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label no-padding-right" for="evalRules">周期类型<font color="red">*</font></label>
				<div class="col-sm-3">
					<input type="hidden" id="cell3Id"   value="${excelData.cell3}" placeholder="评价" class="form-control" required >
					   <select name="cell3" id="theruleName" onchange="chanceSelect(this.options[this.options.selectedIndex].value,'')">
						   <option value="">请选择</option>
						   <option value="多时限">多时限</option>
						   <option value="单时限">单时限</option>
						   <option value="天">天</option>
						   <option value="周">周</option>
						   <option value="月">月</option>
						   <option value="季度">季度</option>
					   </select>
				</div>
			</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="evalRules">时限<font color="red">*</font></label>
			<div class="col-sm-5" id="shijianxuanxiang">
				<input type="text" name="cell4"   value="${excelData.cell4}" class="form-control chance2_1_17" required >
			</div>
		</div>
		</div>
	</div>
	<input type="hidden" name="sysId" id="excel_id"   class="form-control chance2_1_17">

</form:form>

<script>
	var theid = ""
	var idArr = []
	sessionStorage.setItem("lxStatus",0);
	$.ajax({
		url:'/excel/data/getFailList?batchNum='+$("#pt-batchNum").val(),
		dataType:'json',
		type:'get',
		contentType:'application/json',
		success:function (res) {
			idArr = res.data.failList
			console.log(idArr)
			var danyan = setInterval(function(){
				if(theid>idArr.length-1){
					alert("已经是最后一条！")
					clearInterval(danyan)
				}else if(theid != sessionStorage.getItem("thefailList")){
					theid = sessionStorage.getItem("thefailList")
					var params = {
						"sysId":idArr[theid]
					}
					console.log(params)
					$.ajax({
						url:'/excel/data/getById',
						dataType:'json',
						type:'POST',
						data:JSON.stringify(params),
						contentType:'application/json',
						success:function (res) {
							console.log("danyanji")
							console.log(res)
							// var html = "<input type=\"text\" name=\"cell4\" class=\"form-control chance2_1_17\" required >"
							// $("#shijianxuanxiang").html(html)
							$(".chance_remarks").val(res.data.remarks?res.data.remarks:"")
							$(".chance1_1_17").val(res.data.cell0?res.data.cell0:"")
							// $(".chance2_1_17").val(res.data.cell4)
							$("#cell3Id").val(res.data.cell3?res.data.cell3:"")
							$("#qiantoushuju").val(res.data.cell6?res.data.cell6:"")
							$("#xiebanshuju").val(res.data.cell7?res.data.cell7:"")
							$("#caosongshuju").val(res.data.cell8?res.data.cell8:"")
							$("#excel_id").val(res.data.sysId?res.data.sysId:"")
							$("select[name='cell10']").val(res.data.cell10?res.data.cell10.replace(",",""):"")
							getTheInfo()
							chanceSelect(res.data.cell3,res.data.cell4)
						}
					});
				}
			},1000)
		}
	});
</script>
<script>
		function getTheInfo(){
			var theruleNames = document.getElementById("theruleName").children
			var cell3Id = document.getElementById("cell3Id").value
			for (let i = 0; i < theruleNames.length; i++) {
				if(theruleNames[i].value == cell3Id){
					theruleNames[i].selected = "selected"
				}
			}
			$.ajax({
				type:"POST",
				data:{deptId:""},
				url:"/taskMain/cbDeptList/",
				async:false,
				success:function (data) {
					console.log("yyyyyyyyy")
					console.log(data)
					danwei = "";
					danweiArr = [];
					for (var i = 0; i<data.length; i++){
						danwei += " <option value=\""+ data[i].sysId +"\">"+data[i].deptName +"</option>";
						danweiArr.push({danweiSysId:data[i].sysId,danweiName:data[i].deptName});
					}
					var htmlqiantou = "<div class=\"col-sm-12\">\n" +
							"                <select multiple=\"true\"  class=\"qiantoutanchaung\" onchange='qiantouMonitor(this)'> "+ danwei + "</select>\n" +
							"               <input type='hidden' value='' name=\"cell6\">\n" +
							"            </div>\n"
					$("#qiantoudanweiid").html(htmlqiantou)
					var htmlxieban= "<div class=\"col-sm-12\">\n" +
							"                <select multiple=\"true\"  class=\"xiebantanchaung\" onchange='xiebanMonitor2(this)'> "+ danwei + "</select>\n" +
							"               <input type='hidden' value='' name=\"cell7\">\n" +
							"            </div>\n"
					// cell5
					$("#xiebandanweiid").html(htmlxieban)
					$(".qiantoutanchaung").select2({
						placeholder: "请输入或点击选择牵头单位",
						width: "100%",
						closeOnSelect: false,
						allowClear: true,
					});
					$(".xiebantanchaung").select2({
						placeholder: "请输入或点击选择协办单位",
						width: "100%",
						closeOnSelect: false,
						allowClear: true,
					});
					var qiantoushuju = document.getElementById("qiantoushuju").value.split(",")
					var xiebanshuju = document.getElementById("xiebanshuju").value.split(",")
					$(".qiantoutanchaung").val(qiantoushuju).trigger('change')
					$(".xiebantanchaung").val(xiebanshuju).trigger('change')
				}
			})
			$.ajax({
				url:"/taskMain/leaderList/",
				async:false,
				success:function (data) {
					var  xianlingdao = ""
					for (var i = 0; i<data.length;i++ ){
						xianlingdao += " <option value=\""+ data[i].sysId +"\">"+data[i].name +"</option>";
					}
					var  caosonghtml =   "            <div class=\"col-sm-12\">\n" +
							"                <select multiple=\"true\" id=\"e1\" name=\"\" class=\"caosongtanchuang\" onchange=\"caosongCC(this)\">"+ xianlingdao +"</select>\n" +
							"                    <input type=\"hidden\" value=\"\" name=\"cell8\">\n" +
							"                </div>\n" +
							"           </div>"
					$("#caosonglingdaoid").html(caosonghtml)
					$(".caosongtanchuang").select2({
						placeholder: "请输入或点击选择抄送领导",
						width: "100%",
						closeOnSelect: false,
						allowClear: true,
					});
					var caosongshuju = document.getElementById("caosongshuju").value.split(",")
					$(".caosongtanchuang").val(caosongshuju).trigger('change')
				}
			})
		}
		function caosongCC(data) {
			console.log(data)
			$(data).siblings("input").val($(data).val().join(","));
		}
		function qiantouMonitor(data)  {
			sessionStorage.setItem("lxStatus",1);
			var $data = $(data).val();//获取全部select的值
			console.log($data)
			//临时数组存放
			var tempArray1 = []; //临时数组1
			var tempArray2 = []; //临时数组2
					for (var i = 0; i < $data.length; i++) {
				tempArray1[$data[i]] = true; //将数array2 中的元素值作为tempArray1 中的键，值为true；
			}
			for (var i = 0; i < danweiArr.length; i++) {
				if (!tempArray1[danweiArr[i].danweiSysId]) {
					tempArray2.push(danweiArr[i]); //过滤array1 中与array2 不相同的元素；
				}
			}
			var xieban;
			for (var i = 0; i<tempArray2.length; i++){
				xieban +=  " <option value=\""+ tempArray2[i].danweiSysId +"\">"+tempArray2[i].danweiName +"</option>"
			}
			$(data).parent().parent().siblings().find("select.xieban").html(xieban);
			$(data).siblings("input").val($(data).val().join(","));
		}
		function xiebanMonitor2(data)  {
			sessionStorage.setItem("lxStatus",1);
			var $data = $(data).val();//获取全部select的值
			//临时数组存放
			var tempArray1 = []; //临时数组1
			var tempArray2 = []; //临时数组2
			for (var i = 0; i < $data.length; i++) {
				tempArray1[$data[i]] = true; //将数array2 中的元素值作为tempArray1 中的键，值为true；
			}
			for (var i = 0; i < danweiArr.length; i++) {
				if (!tempArray1[danweiArr[i].danweiSysId]) {
					tempArray2.push(danweiArr[i]); //过滤array1 中与array2 不相同的元素；
				}
			}
			var xieban;
			for (var i = 0; i<tempArray2.length; i++){
				xieban +=  " <option value=\""+ tempArray2[i].danweiSysId +"\">"+tempArray2[i].danweiName +"</option>"
			}
			$(data).parent().parent().siblings().find("select.xieban").html(xieban);
			$(data).siblings("input").val($(data).val().join(","));
		}
</script>
<script>
	function chanceSelect(data,thevalue){
		var xuanxianghtml = ""
		if(data == "多时限"){
			var valuehtml = ""
			if(thevalue != null && thevalue!= undefined && thevalue!=""){
				var valueArr = thevalue.split(",")
				for (var i = 0; i < valueArr.length; i++) {
					valuehtml +=	"    <div class=\"col-sm-8\">\n" +
							"        <input type=\"text\" placeholder=\"年-月-日\"  onchange=\"changeValue()\"  value = "+ valueArr[i] + "  onblur=\"addTimeBtnData()\"     class=\"form-control Zdate_picker danyan\" readonly>\n" +
							"    </div>\n"
				}
			}else{
				valuehtml =	"    <div class=\"col-sm-8\">\n" +
						"        <input type=\"text\" placeholder=\"年-月-日\"  onchange=\"changeValue()\"  onblur=\"addTimeBtnData()\"     class=\"form-control Zdate_picker danyan\" readonly>\n" +
						"    </div>\n"
			}
			xuanxianghtml = "<div class='form-group'>" +
					valuehtml +
					"    <div class=\"col-sm-1 addTime\">\n" +
					"        <input type=\"button\" class=\"btn btn-sm btn-success\" onclick='addTimeBtn(this)' value=\"添加时限\">\n" +
					"        <input id=\"cell4Id\" type=\"hidden\" name=\"cell4\" class=\"form-control\" >\n" +
					"    </div>\n" +
					"    </div>"
		}
		if(data == "单时限"){
			if(thevalue == ""){
				xuanxianghtml = "<div class='form-group'>" +
						"    <div class=\"col-sm-8\">\n" +
						"        <input type=\"text\" class=\"form-control Zdate_picker transform\"  onchange=\"changeValue()\"   value = \"\"   name=\"cell4\" readonly>\n" +
						"    </div>\n" +
						"    </div>"
			}else{
				xuanxianghtml = "<div class='form-group'>" +
						"    <div class=\"col-sm-8\">\n" +
						"        <input type=\"text\" class=\"form-control Zdate_picker transform\"  onchange=\"changeValue()\"   value = "+ thevalue + "   name=\"cell4\" readonly>\n" +
						"    </div>\n" +
						"    </div>"
			}
		}
		if(data == "天"){
			if(thevalue == ""){
				xuanxianghtml = "<input type=\"number\" class=\"form-control\" min='0' name=\"cell4\" onchange=\"changeValue()\"   value = \"\"   placeholder=\"请输入天数\">"
			}else{
				xuanxianghtml = "<input type=\"number\" class=\"form-control\" min='0' name=\"cell4\" onchange=\"changeValue()\"   value = "+ thevalue + "   placeholder=\"请输入天数\">"
			}
		}
		if(data == "周"){
			if(thevalue == ""){
				xuanxianghtml  = "      <select name=\"cell4\" class=\"form-control\"  onchange=\"changeValue()\"    value = \" \"  >\n" +
						"            <option value=\"1\">星期一</option>\n" +
						"            <option value=\"2\">星期二</option>\n" +
						"            <option value=\"3\">星期三</option>\n" +
						"            <option value=\"4\">星期四</option>\n" +
						"            <option value=\"5\">星期五</option>\n" +
						"            <option value=\"6\">星期六</option>\n" +
						"            <option value=\"7\">星期日</option>\n" +
						"        </select>"
			}else{
				xuanxianghtml  = "      <select name=\"cell4\" class=\"form-control\" onchange=\"changeValue()\"    value = "+ thevalue + "  >\n" +
						"            <option value=\"1\">星期一</option>\n" +
						"            <option value=\"2\">星期二</option>\n" +
						"            <option value=\"3\">星期三</option>\n" +
						"            <option value=\"4\">星期四</option>\n" +
						"            <option value=\"5\">星期五</option>\n" +
						"            <option value=\"6\">星期六</option>\n" +
						"            <option value=\"7\">星期日</option>\n" +
						"        </select>"
			}
		}
		if(data == "月"){
			if(thevalue == ""){
				xuanxianghtml  = "<input type=\"text\" id=\"\"   value = \"\"  onchange=\"changeValue()\"    readonly lay-verify=\"date\" name=\"cell4\" placeholder=\"日\" autocomplete=\"off\" class=\"layui-input dalong form-control\">\n"
			}else{
				xuanxianghtml  = "<input type=\"text\" id=\"\"  onchange=\"changeValue()\"   value = "+ thevalue + "    readonly lay-verify=\"date\" name=\"cell4\" placeholder=\"日\" autocomplete=\"off\" class=\"layui-input dalong form-control\">\n"
			}
		}
		if(data == "季度"){
			if(thevalue == ""){
				xuanxianghtml  = "<input type=\"text\"  onchange=\"changeValue()\"  value = \"\"    readonly lay-verify=\"date\" placeholder=\"年-月-日\" name=\"cell4\" autocomplete=\"off\" class=\"layui-input form-control date_picker\">\n"
			}else{
				xuanxianghtml  = "<input type=\"text\"  onchange=\"changeValue()\"  value = "+ thevalue + "    readonly lay-verify=\"date\" placeholder=\"年-月-日\" name=\"cell4\" autocomplete=\"off\" class=\"layui-input form-control date_picker\">\n"
			}
		}
		addTimeBtnData()
		$("#shijianxuanxiang").html(xuanxianghtml)
	}
	function addTimeBtn(e) {
		var html = " <div class=\"form-group\">" +
				"   <div class=\"col-sm-8\">\n" +
				"       <input  type=\"text\" value=\"\" readonly lay-verify=\"date\" onblur=\"addTimeBtnData()\"    placeholder=\"年-月-日\" autocomplete=\"off\" class=\"layui-input form-control date_picker danyan\">\n" +
				"</div>\n" +
				"    <div class=\"col-sm-1 addTime\">\n" +
				"        <input type=\"button\" class=\"btn btn-sm btn-danger removeTimeBtn\"  value=\"删除时限\">\n" +
				"    </div>"
		"</div>"
		$(e).parent().parent().parent().append(html);
	}

    function addTimeBtnData(){
		setTimeout(function(){
			var value = [];
			$(".danyan").each(function() {
				value.push($(this).val());
			});
			$('#cell4Id').attr('value',value.join(","))
		},200)
	}
	function changeValue(){
		sessionStorage.setItem("lxStatus",1);
	}
	setTimeout(function () {
		sessionStorage.setItem("lxStatus",0);
	},3000)
</script>



